﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ClientModel;

namespace Client
{
    /// <summary>
    /// Interaction logic for pagSettings.xaml
    /// </summary>
    public partial class pagSettings : Page
    {
        private static pagSettings me;

        public pagSettings()
        {
            InitializeComponent();
        }

        public static pagSettings getInstance()
        {
            if (me == null)
            {
                me = new pagSettings();
            }
            me.Init();
            return me;
        }

        public void Init()
        {
            lblAntalBøjleFejl.Visibility = Visibility.Hidden;
            txtAntalBøjler.Text = Service.getInstance().getNumberOfHangers() + "";
        }

        private void btnGem_Click(object sender, RoutedEventArgs e)
        {
            if (IsInteger(txtAntalBøjler.Text))
            {
                if (Int32.Parse(txtAntalBøjler.Text) > 0)
                {
                    Service.getInstance().setNumberOfHangers(Int32.Parse(txtAntalBøjler.Text));
                    lblAntalBøjleFejl.Visibility = Visibility.Hidden;
                }
                else { lblAntalBøjleFejl.Content = "antal skal være over 0"; lblAntalBøjleFejl.Visibility = Visibility.Visible; }
            }
            else { lblAntalBøjleFejl.Content = "antal skal være tal"; lblAntalBøjleFejl.Visibility = Visibility.Visible; }
            txtAntalBøjler.Text = Service.getInstance().getNumberOfHangers() + "";
        }

        private void btnTilbage_Click(object sender, RoutedEventArgs e)
        {
            MainWindow.SetPage(pagSession.getInstance());
        }

        public static bool IsInteger(string theValue)
        {
            try
            {
                Convert.ToInt32(theValue);
                return true;
            }
            catch
            {
                return false;
            }
        }


    }
}
